package MapReduce.writableBean;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @Author:lixinlei
 * @Date:2022/3/24 8:54
 **/
public class BookBorrowWritable implements WritableComparable<BookBorrowWritable> {

    private String bookId = "";
    private String bookName = "";
    private String personId = "";
    private String personName = "";
    private String dateTime = "";
    private String flag = "";

    public String getBookId() {
        return bookId;
    }

    public void setBookId(String bookId) {
        this.bookId = bookId;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getPersonId() {
        return personId;
    }

    public void setPersonId(String personId) {
        this.personId = personId;
    }

    public String getPersonName() {
        return personName;
    }

    public void setPersonName(String personName) {
        this.personName = personName;
    }

    public String getDateTime() {
        return dateTime;
    }

    public void setDateTime(String dateTime) {
        this.dateTime = dateTime;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    @Override
    public int compareTo(BookBorrowWritable o) {
        if (this.bookId.equals(o.getBookId())){
            if(this.personId.equals(o.getPersonId())){
                return this.dateTime.compareTo(o.getDateTime());
            }else{
                return this.personId.compareTo(o.getPersonId());
            }
        }else{
            return this.bookId.compareTo(o.getBookId());
        }
    }

    @Override
    public void write(DataOutput out) throws IOException {

        out.writeUTF(bookId);
        out.writeUTF(bookName);
        out.writeUTF(personId);
        out.writeUTF(personName);
        out.writeUTF(dateTime);
        out.writeUTF(flag);

    }

    @Override
    public void readFields(DataInput in) throws IOException {

        this.bookId = in.readUTF();
        this.bookName = in.readUTF();
        this.personId = in.readUTF();
        this.personName = in.readUTF();
        this.dateTime = in.readUTF();
        this.flag = in.readUTF();

    }

    @Override
    public String toString() {
        return bookId+"\t"+bookName+"\t"+personId+"\t"+personName+"\t"+dateTime;
    }
}
